﻿// <copyright file="MockLogProvider.cs" company="Ecole Normale Supérieure">
// Released under GPLv2
// </copyright>
// <summary>Contains the mock log provider</summary>

namespace Sqwarea.Persistence.Mock
{
    using System.Collections.Generic;
    using System.Linq;

    /// <summary>
    /// Provides a log instance
    /// </summary>
    public class MockLogProvider : ILogProvider
    {
        /// <summary>
        /// Logs list.
        /// </summary>
        private static List<Log> _logs = new List<Log>();

        /// <summary>
        /// Saves a log.
        /// </summary>
        /// <param name="log">The log to be saved.</param>
        public void StoreLog(Log log)
        {
            MockLogProvider._logs.Add(log);
        }

        /// <summary>
        /// Deletes the logs given in parameter from the Log table
        /// All given logs must have the same KingId
        /// </summary>
        /// <param name="logs">list of logs to be removed from the Table</param>
        public void DeleteLogs(IEnumerable<Log> logs)
        {
            foreach (var log in logs)
            {
                MockLogProvider._logs.Remove(log);
            }
        }

        /// <summary>
        /// Gets the logs of kingId user.
        /// </summary>
        /// <param name="kingId">Id of the required king</param>
        /// <returns>See summary</returns>
        public IEnumerable<Log> GetLogs(long kingId)
        {
            return from log in MockLogProvider._logs
                          where log.KingId == kingId
                           select log;
        }

        // Clear all

        /// <summary>
        /// Clear all data (used only for tests purpose)
        /// </summary>
        internal void ClearAll()
        {
            _logs.Clear();
        }
    }
}
